package editor;

import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.JRadioButton;

public class DialogScegliOperazione extends JDialog implements ActionListener {
		JRadioButton radioNuovo;
		JRadioButton radioApri;
		JButton ok;
		JButton annulla;
		ButtonGroup gruppo;
		EditorFrame ef;
		
	public DialogScegliOperazione(EditorFrame ef){
		this.ef = ef;
		JPanel p=new JPanel();
		JPanel pOk=new JPanel();
		JPanel pAnn=new JPanel();
		this.getContentPane().add(p);
		p.setLayout(new GridLayout(2,2));
		ok = new JButton("Ok");
		ok.addActionListener(this);
		ok.setPreferredSize(new Dimension(90,30));
		annulla = new JButton("Annulla");
		annulla.addActionListener(this);
		annulla.setPreferredSize(new Dimension(90,30));
		radioNuovo = new JRadioButton("Crea nuovo livello",true);
		radioNuovo.addActionListener(this);
		radioApri = new JRadioButton("Apri livello esistente",false);
		radioApri.addActionListener(this);
		gruppo = new ButtonGroup();
		gruppo.add(radioNuovo);
		gruppo.add(radioApri);
		pOk.add(ok);
		pAnn.add(annulla);
		p.add(radioNuovo);
		p.add(pOk);
		p.add(radioApri);
		p.add(pAnn);
		
		this.setTitle("Benvenuto");
		this.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
		this.setSize(300,130);
		this.setLocation(500,300);
		this.setAlwaysOnTop(true);
		this.setVisible(true);
	}
	public void actionPerformed(ActionEvent e) {
		if(e.getSource() == ok){
			if(radioNuovo.isSelected()){
				new DialogNuovoLivello(this.ef);
			}
			else if(radioApri.isSelected()){
				new DialogApriLivello(this.ef);
			}
			this.dispose();
		}
		else if (e.getSource() == annulla){
			this.dispose();
		}		
	}

}
